package com.leave.service.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.leave.dao.RoleMapper;
import com.leave.entity.Role;
import com.leave.service.IRoleService;
@Service
public class RoleServiceImpl implements IRoleService{
	@Autowired
	private RoleMapper roleMapper;
	
	
	/**
	 * 获取所有角色
	 */
	public List<Role> getAllRole() {
		return roleMapper.getAllRole();
	}

	/**
	 * 根据登录明获取角色实例
	 */
	public Set<Role> getRoleByLoginName(String loginName) {
		Set<Role> roleSet = roleMapper.getRoleByLoginName(loginName);
		
		return roleSet;
	}
	
	/**
	 * 根据登录名获取角色名称
	 */
	public Set<String> getRoleNameByLoginName(String loginName) {
		Set<String> roleSet = roleMapper.getRoleNameByLoginName(loginName);
		return roleSet;
	}

	public HashMap<String, Object> getAllRoleByPage(Integer page, Integer rows) {
		PageHelper.startPage(page,rows);
		List<Role> roleList = roleMapper.getAllRole();
		PageInfo<Role> pageInfo = new PageInfo<Role>(roleList);
		Long total = pageInfo.getTotal();
		HashMap<String,Object> map = new HashMap<String,Object>();
		map.put("roleList", roleList);
		map.put("total", total);
		return map;
	}

	public Role getRoleByroleId(Integer roleId) {
		Role r = roleMapper.selectByPrimaryKey(roleId);
		return r;
	}

	public int removeRoleByArrId(int[] arrId) {
		int i = roleMapper.deleteByArrId(arrId);
		return i;
	}

	public Role getRoleByRoleName(String roleName) {
		Role r = roleMapper.selectByRoleName(roleName);
		return r;
	}

	public int addRole(Role r) {
		int i = roleMapper.insertSelective(r);
		return i;
	}

	public int updateRoleByRole(Role r) {
		int i = roleMapper.updateByPrimaryKeySelective(r);
		return i;
	}

}
